package com.easycoding.framework.util;

import java.util.Properties;

/**
 * <b>Description</b>:属性文件操作类<br/>
 * <b>Information</b>: 对外承接网站制作,价格优惠,服务一流,强有力的技术支持,asp,Jsp,Hibernate,Struts2,MS SQLServer,Oracle,jQuery,Css+div布局,Dhtml<br/>
 * <b>Create Date</b>: Nov 3, 2008 3:11:16 PM<br/>
 * <b>Version</b>: Since JDK 1.5.0<br/>
 * <b>Package</b>: com.easycoding.framework.util
 */
public class PropertiesHelper
{
	private Properties properties;

	public PropertiesHelper(Properties properties)
	{
		this.properties = properties;
	}

	public String get(String key)
	{
		return properties.getProperty(key);
	}

	public String get(String key,String defaultVal)
	{
		String val = get(key);
		return val == null ? defaultVal : val;
	}

	public String findValue(String... keys)
	{
		for(String key : keys)
		{
			String value = get(key);
			if(value != null)
			{
				return value;
			}
		}
		return null;
	}

	public boolean getBoolean(String key,boolean defaultVal)
	{
		String val = get(key);
		return val == null ? defaultVal : Boolean.parseBoolean(val);
	}

	public long getLong(String key,long defaultVal)
	{
		String val = get(key);
		return val == null ? defaultVal : Long.parseLong(val);
	}

	public int getInt(String key,int defaultVal)
	{
		return (int)getLong(key,defaultVal);
	}

	public double getDouble(String key,double defaultVal)
	{
		String val = get(key);
		return val == null ? defaultVal : Double.parseDouble(val);
	}

	public <T extends Enum<T>>T getEnum(String key,Class<T> type,T defaultValue)
	{
		String val = get(key);
		return val == null ? defaultValue : Enum.valueOf(type,val);
	}
}
